<style>
.NoteItemDiv{
	float: left;
	color: #468;
	width: 145px;
	position: relative;
	display: inline-table;
	margin: -2px 5px 8px 5px;
}
.NoteItemListTd{
	padding: 8px;
}
.NoteItemTitleTd{
	text-align: left;
	padding-left: 4px;
}
.NoteItemListIcon{
	width: 16;
	height: 16px;
}
.NoteItemTitleTd a{
	text-decoration: none;
}
.NoteItemFolderLabel{
	width: 100%;
	color: #229933;
	font-size: 1.2rem;
	font-weight: bold;
	padding-left: 6px;
	margin-bottom: 8px;
	border-bottom: 1px solid #999;
}
#NoteItemListDiv{
	padding: 1vw 1vw;
}
#NoteItemListTable{
	width: 100%;
}
</style>

<div id='NoteItemListDiv'>
	<table id='NoteItemListTable'/>
</div>

<script>

var dbid = null;

getVue('NoteItemListDiv');

function getNoteItemString(dbid, item){
	if (dbid == null) dbid = '';

	return "<div class='NoteItemDiv'><table><tr>"
		+ "<td><img class='NoteItemListIcon' src='" + item.icon + "'/></td>"
		+ "<td class='NoteItemTitleTd'><a class='NoteItemListLink' target='_blank' href='/sharenote?dbid=" + dbid + "&id=" + item.id + "'>" + item.title + "</a></td>"
		+ "</tr></table></div>"
}

function addNoteItemList(folder, line){
	$('#NoteItemListTable').append("<tr><td class='NoteItemListTd'><div class='NoteItemFolderLabel'>" + folder + "</div>" + line + "</td></tr>");
}

function loadNoteItemList(){
	$('#NoteItemListTable').html('');

	getHttpResult('/getnotelist', null, function(data){
		if (data.code == XG_TIMEOUT){
			sessionTimeout();
		}
		else if (data.code < 0){
			showToast('加载数据失败');
		}
		else{
			var line = '';
			var folder = '';

			$.each(data.list, function(idx, item){
				if (folder.length == 0 || folder == item.folder){
					line += getNoteItemString(data.dbid, item);
				}
				else{
					addNoteItemList(folder, line);
					line = getNoteItemString(data.dbid, item);
				}

				folder = item.folder;
			});

			if (line.length > 0) addNoteItemList(folder, line);
		}
	});
}

loadNoteItemList();

</script>
